1 /** 2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved. 3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This module contains functionality for logging analyzer results to files. 7 */ 8 module code_checker.engine.logger; 9 10 import code_checker.types : AbsolutePath; 11 12 @safe: 13 14 struct Logger { 15 private { 16 AbsolutePath logdir; 17 } 18 19 this(AbsolutePath p) { 20 this.logdir = p; 21 } 22 23 void setup() { 24 import std.file : mkdirRecurse, exists; 25 26 if (!exists(logdir)) 27 mkdirRecurse(logdir); 28 } 29 30 /** Log `content` to a file in logdir with a filename derived from f. 31 * 32 */ 33 void put(const AbsolutePath f, const string[][] content) @trusted { 34 import std.algorithm : joiner; 35 import std.path : pathSplitter, buildPath; 36 import std.range : dropOne; 37 import std.stdio : File; 38 import std.utf : toUTF8; 39 40 setup(); 41 42 string lfile = buildPath(logdir, f.dup.dropOne.pathSplitter.joiner("_").toUTF8 ~ ".txt"); 43 auto fout = File(lfile, "w"); 44 45 foreach (l; (cast(string[][]) content).joiner) 46 fout.writeln(l); 47 } 48 }